package com.smallcr.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Maps;
import com.smallcr.annotation.IgnoreAuth;
import com.smallcr.doc.SessionKeys;
import com.smallcr.utils.ResponseBodyResult;
import com.smallcr.utils.ResponseResult;
import com.smallcr.utils.UUIDUtils;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController{

	
	/**
	 * @Title: login @Description: 医生登录 @param:mobile 手机号码 @param:password
	 * 登录密码 @param:deviceNumber 设备号 @return:ResponseResult @throws
	 */
	@IgnoreAuth
	@PostMapping("login")
	@ApiOperation(value = "测试登录接口", notes = "测试登录接口", response = ResponseResult.class)
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "string", name = "mobile", value = "手机号码", required = true)})
	public ResponseResult login(@RequestParam String mobile) {
		logger.info("参数 用户名:" + mobile );
		/** 登录成功，返回Token **/
		String userId=(String) getRequest().getAttribute(SessionKeys.UID.toString());
		Map<String, Object> sessionMap =Maps.newHashMap();
		sessionMap.put("mobile", mobile);
		sessionMap.put("userId", userId);
		sessionMap.put("token", UUIDUtils.UUID());
		return ResponseBodyResult.success(sessionMap);
	}
	
	@PostMapping("index")
	@ApiOperation(value = "测试接口", notes = "测试接口", response = ResponseResult.class)
	@ApiImplicitParams({
		@ApiImplicitParam(paramType = "header", dataType = "string", name = "X-SMALLCR-SESSION", value = "应用码:smallcr-pupil", required = true),
		@ApiImplicitParam(paramType = "header", dataType = "string", name = "X-SMALLCR-APPCODE", value = "会话Token", required = true)})
	public ResponseResult index() {
		String userId=(String) getRequest().getAttribute(SessionKeys.UID.toString());
		Map<String, Object> sessionMap =Maps.newHashMap();
		sessionMap.put("userId", userId);
		return ResponseBodyResult.success(sessionMap);
	}
}
